//
//  Stone.m
//  Return Of The Lemi
//
//  Created by Paul Vishayanuroj on 12/10/09.
//  Copyright 2009 Paul Vishayanuroj. All rights reserved.
//

#import "Pebble.h"


@implementation Pebble

+ (id) pebbleWithPosition:(CGPoint)pos space:(cpSpace *)space
{
	return [[[self alloc] initWithPosition:pos space:space] autorelease];
}

- (id) initWithPosition:(CGPoint)pos space:(cpSpace *)space
{
	if ((self = [super init]))
	{
		sprite = [[Sprite spriteWithFile:@"Stone.png"] retain];
		[sprite setScale:CONST_PEBBLE_SCALE];
		[sprite setPosition:pos];
		
		counter = 5;
		
		// Create the kumquat body with given mass and moment of inertia
		body = cpBodyNew(CONST_PEBBLE_MASS, cpMomentForCircle(CONST_PEBBLE_MASS, 0.0f, CONST_PEBBLE_RADIUS, cpvzero));
		
		// Set the initial position
		body->p = cpv(pos.x - 15, pos.y + 30);
		
		// Give it an angle
		cpBodySetAngle(body, 1.5f);
		
		// Give it an initial velocity
		body->v = cpv(-100.0f, 300.0f);
		
		// Set an angular velocity (how fast it's rotating)
		body->w = CONST_PEBBLE_ANG_VEL;
		
		// Add the body to space
		cpSpaceAddBody(space, body);
		
		// Create our shape associated with the ball's body
		shape = cpCircleShapeNew(body, CONST_PEBBLE_RADIUS, cpvzero);
		
		shape->e = 0.8f; // Elasticity
		
		shape->u = 1.0f; // Friction
		
		shape->data = self; // Associate with kumquat object
		
		shape->collision_type = cTagEnemyMunitions; // Collisions are grouped by types	
		
		// Add the shape to our space
		cpSpaceAddShape(space, shape);			
	}
	return self;
}

- (void) dealloc
{
	[sprite dealloc];
	[super dealloc];
}

@end
